package JsoupXmlDtd;

/*
   XPath查询: XPath为xml路径语言,是一种用来确定XML(标准通用标记语言的子集)文档中某部分位置的语言
       *使用Jsoup的XPath需要额外带入jar包
       *需要进行w3school参考手册,使用xpath的语法完成查询

*/


import cn.wanghaomiao.xpath.exception.XpathSyntaxErrorException;
import cn.wanghaomiao.xpath.model.JXDocument;
import cn.wanghaomiao.xpath.model.JXNode;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.lang.String;

public class demo05_Jsoup {
    public static void main(String[] args) throws IOException, XpathSyntaxErrorException {
        //2获取Document对象
        //2.1获取03_student.xml的路径path
        String aa = demo05_Jsoup.class.getClassLoader().getResource("03_student.xml").getPath();
        //2.2解析xml文档,加载文档进内存,获取dom树--->Document
        Document bb = Jsoup.parse(new File(aa), "utf-8");

        //根据document对象,创建JXDocument对象
        JXDocument cc=new JXDocument(bb);

        //结合xpath语法查询
        List<JXNode> dd = cc.selN("//student");
        for (JXNode ee : dd){
            System.out.println(ee);
        }
        System.out.println("=================");

        //查询所有student标签下的那么标签
        List<JXNode> ff = cc.selN("//student/name");
        for (JXNode mm : ff){
            System.out.println(mm);
        }
        System.out.println("======================");

        //查询student标签下带有id属性值的name标签
        List<JXNode> hh = cc.selN("//student/name[@id]");
        for (JXNode kk : hh){
            System.out.println(kk);
        }
        System.out.println("===============");

       //查询student标签下带有id属性的name标签,并且id属性值为itcast
        List<JXNode> ss = cc.selN("//student/name[@id='itcast]");
        for (JXNode ww : ss){
            System.out.println(ww);
        }


    }
}
